use crate::constant::{Star, StarInfo};
use crate::model::atmosphere::Atmosphere;

/// 地球质量 单位kg
const MASS: f64 = 5.965e+24;
/// 地球半径 单位m
const RADIUS: f64 = 6.371e+6;
/// 地球大气气体常数
const ATMOSPHERIC_GAS: f64 = 287.05;

pub struct Earth;

impl Star for Earth {
    fn catch_atmosphere(&self, altitude: f64) -> Atmosphere {
        if altitude < 15000.0 {
            Atmosphere {
                name: "对流层".to_string(),
                air_pressure: (1000.0 - altitude / 1000.0 * 13.333) * 100.0,
                temperature: 300.0 - altitude / 1000.0 * 6.5,
            }
        } else if altitude < 50000.0 {
            Atmosphere {
                name: "平流层".to_string(),
                air_pressure: (800.0 - (altitude - 15000.0) / 1000.0 * 22.828) * 100.0,
                temperature: 200.0 + (altitude - 15000.0) / 1000.0 * 1.4,
            }
        } else if altitude < 85000.0 {
            Atmosphere {
                name: "中间层".to_string(),
                air_pressure: (1.0 - (altitude - 50000.0) / 1000.0 * 0.0282) * 100.0,
                temperature: 270.0 - (altitude - 50000.0) / 1000.0 * 2.571,
            }
        } else {
            Atmosphere {
                name: "电离&逸散&外空".to_string(),
                air_pressure: 0.0,
                temperature: 0.0,
            }
        }
    }

    fn info(&self) -> StarInfo {
        StarInfo {
            mass: MASS,
            radius: RADIUS,
            atmospheric_gas: ATMOSPHERIC_GAS,
        }
    }
}
